import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JButton;


public class BoutonsFonctions extends JPanel {
	private static final long serialVersionUID = 1L;

	private Command fonctionCourante;
	private PropertyChangeSupport changes;
	
	public BoutonsFonctions()
	{
		changes = new PropertyChangeSupport(this);
		//setLayout(new GridLayout(8,1));
		
		GridBagLayout g = new GridBagLayout();
		setLayout(g);
		GridBagConstraints c = new GridBagConstraints () ;
		c.fill = GridBagConstraints.BOTH ; 
		c.weightx = 0 ;
		c.gridwidth = GridBagConstraints.REMAINDER ;
		JButton temp = new JButton(new ImageIcon("images/iconDessin.png"));
		temp.addActionListener(new ButtonListener(new cmdDessiner()));
		g.setConstraints(temp,c);
		add(temp);
		temp = new JButton(new ImageIcon("images/iconDeplacer.png"));
		temp.addActionListener(new ButtonListener(new cmdDeplacer()));
		g.setConstraints(temp,c);
		add(temp);
		/*temp = new JButton(new ImageIcon("images/iconVert.png"));
		temp.addActionListener(new ButtonListener("supprimer"));
		g.setConstraints(temp,c);
		add(temp);*/
	}
	
	/* Accessors */
	public void setCurrentButton(Command c)
	{
		Command oldFonction = fonctionCourante;
		fonctionCourante = c;
		changes.firePropertyChange("Fonction", oldFonction, fonctionCourante);
	}
	
	public void addPropertyChangeListener(PropertyChangeListener l)
	{
		changes.addPropertyChangeListener(l);
	}
	
	public void removePropertyChangeListener(PropertyChangeListener l)
	{
		changes.removePropertyChangeListener(l);
	}
	
	/* Action Listeners Methods */
	class ButtonListener implements ActionListener {

		Command fonction;
		
		public ButtonListener(Command c)
		{
			fonction = c;
		}
		
		@Override
		public void actionPerformed(ActionEvent e) {
			BoutonsFonctions.this.setCurrentButton(fonction);
		}
		
	}
}
